home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / assignBakeSet.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  3.7 KB  |  130 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. //  MODIFY THIS AT YOUR OWN RISK
  19. //
  20. //  Description:
  21. //      This script assigns objects to bakeSets.
  22. //
  23.  
  24.  
  25. global proc assignBakeSet (string $bakeSet, string $item)
  26. {
  27.     string $assignString = $item;
  28.  
  29.     // No bake set ?
  30.     if ($bakeSet == "") 
  31.     {
  32.         error( "assignBakeSet: No bake set named." );
  33.     }
  34.  
  35.     string $objs[];
  36.  
  37.     if ($item == "")
  38.     {
  39.         // No object was specified in the call to this procedure, so we will
  40.         // assign the bakeSet to whatever is on the current selection list 
  41.         // instead.
  42.         //
  43.         $objs = `ls -dag -objectsOnly -geometry -selection`;
  44.         if (size ($objs) == 0)
  45.         {
  46.             error( "Nothing selected." );
  47.         }
  48.  
  49.         $assignString = "the selected shapes";
  50.  
  51.         if( `nodeType $bakeSet` == "vertexBakeSet" )
  52.         {
  53.             string $meshes[] = `ls -typ mesh $objs`;
  54.             if( size($meshes) < size($objs) )
  55.             {
  56.                 warning( "Ignoring non-poly objects in selection list." );
  57.                 $objs = $meshes;
  58.             }
  59.         }
  60.     }
  61.     else
  62.     {
  63.         //
  64.         // The $item is always an object, never a component (ie face).
  65.         // If the current selection contains faces of the specified item, then
  66.         // we would rather assign the new bakeSet to the specifically selected
  67.         // faces rather than the object as a whole. In particular, this allows
  68.         // users to select faces of a poly object and use the RMB menu to
  69.         // assign them to bakeSets.
  70.         // 
  71.  
  72.         string $selection[] = `ls -selection`;
  73.         int $i;
  74.  
  75.         for ($i = 0; $i < size($selection); $i++)
  76.         {
  77.             if (`match ($item + "\\.f\\[.*\\]") $selection[$i]` != "")
  78.             {
  79.                 // One part of the currently selection is faces of the
  80.                 // specified item. We will add the selected faces to the list
  81.                 // of objects to which the bakeSet will be assigned.
  82.                 //
  83.                 $objs[size($objs)] = $selection[$i];
  84.                 $assignString = ("the selected faces of " + $item);
  85.             }
  86.         }
  87.  
  88.         if (size($objs) == 0)
  89.         {
  90.             // Try again with the shape. Face selection will be names
  91.             // after the shape when other shapes are parented below the
  92.             // transform.
  93.             string $shapes[] = `listRelatives -s $item`;
  94.             if (size($shapes) > 0 )
  95.             {
  96.                 string $shape = $shapes[0];
  97.                 for ($i = 0; $i < size($selection); $i++)
  98.                 {
  99.                     if (`match ($shape + "\\.f\\[.*\\]") $selection[$i]` != "")
  100.                     {
  101.                         $objs[size($objs)] = $selection[$i];
  102.                         $assignString = ("the selected faces of " + $shape);
  103.                     }
  104.                 }
  105.             }
  106.         }
  107.  
  108.         if (size($objs) == 0)
  109.         {
  110.             // There were no faces of the specified item in the current
  111.             // selection. Therefore, we will assign the bakeSet to the 
  112.             // entire object specified, more precisely, to object itself
  113.             // if the object is a shape, or all the shapes under the 
  114.             // object if the object is a transform.
  115.             //
  116.             $objs = `ls -dag -objectsOnly -geometry $item`;
  117.         }
  118.     }
  119.  
  120.     sets -forceElement $bakeSet $objs;
  121.  
  122.     print (
  123.         "// Result: Assigned " 
  124.         + $assignString 
  125.         + " to " 
  126.         + $bakeSet 
  127.         + ". //\n");
  128. }
  129.  
  130.